﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Zhongchouwwwww.Models;

namespace Zhongchouwwwww.webform
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        public static bool IsTrue = true;
        public static List<CommentInfoDTO> comments = new List<CommentInfoDTO>();
        public static Dictionary<string, List<string>> commentsNameImgs = new Dictionary<string, List<string>>();
        public static List<CommentInfoDTO> _tocomments = new List<CommentInfoDTO>();
        protected void Page_Load(object sender, EventArgs e)
        {
            //评论表
            string sqlcom = $"select * from CommentInfo where projectid = '{1}'";
            var comDate = BAL.GetDate.GetCommentInfoDates(sqlcom);
            comments = comDate.Where(ae => {
                if (ae.tocommentid == 0 && ae.Touserid == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }).ToList();
            _tocomments = comDate.Where(ae => {
                if (ae.tocommentid == 0 && ae.Touserid == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }).ToList();
            //根据用户id获取用户名称和头像  添加首次评论的内容
            commentsNameImgs.Clear();
            for (int i = 0; i < comments.Count; i++)
            {
                string name = BAL.GetDate.db.Database.SqlQuery<string>($"select usernikename from Userinfo where userid = {comments[i].Userid}").First();
                string img = BAL.GetDate.db.Database.SqlQuery<string>($"select imgurl from Userinfo where userid = {comments[i].Userid}").First();
                commentsNameImgs.Add(comments[i].Commentvalues,
                new List<string>() { comments[i].Commentid.ToString(), img, name, comments[i].Userid, comments[i].PastTime, });
            }
            //commentsNameImgs数据结构 ：   key：评论  values：List<string> 
            //第一是此评论的评论ID 0
            //第二是用户名头像  
            //第三是用户昵称
            //第四是此评论来着哪个用户  用户id 3
            //第五是此评论发送时间  已格式化后
            //第六是此评论的回复用户名
            //第七是此评论的回复详情值
            //第八是此评论的回复发送时间
            for (int i = 0; i < _tocomments.Count; i++)
            {
                foreach (var item in commentsNameImgs.Values)
                {
                    if (_tocomments[i].tocommentid.ToString() == item[0] && _tocomments[i].Touserid.ToString() == item[3])
                    {
                        var aa = BAL.GetDate.db.Userinfo.Where(ac => ac.userid == int.Parse(_tocomments[i].Userid)).FirstOrDefault();
                        if (aa != null)
                        {
                            item.Add(aa.usernikename);
                        }
                        else
                        {
                            item.Add("用户用户");
                        }
                        item.Add(_tocomments[i].Commentvalues);
                        item.Add(_tocomments[i].PastTime);
                    }
                }
            }
            commentsNameImgs.Values.Where(ac => { return ac[0] == ""; }).First();
            ACEACE.DataSource = commentsNameImgs;
            ACEACE.DataBind();


        }

        protected void FileUpload1_Disposed(object sender, EventArgs e)
        {
           
        }

        protected void Btnok_Click(object sender, EventArgs e)
        {
            
        }

        protected void city1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (city1.SelectedValue)
            {
                case "广西":
                    city2.DataSource = null;
                    city2.Items.Add("南宁");
                    city2.Items.Add("玉林");
                    city2.Items.Add("桂林");
                    break;
                case "广东":
                    city2.DataSource = null;
                    city2.Items.Add("广州");
                    city2.Items.Add("深圳");
                    city2.Items.Add("东莞");
                    break;
                case "上海":
                    city2.DataSource = null;
                    city2.Items.Add("黄浦区");
                    city2.Items.Add("徐汇区");
                    city2.Items.Add("虹口区");
                    break;
                default:
                    break;
            }
            
        }

        protected void textxt_TextChanged(object sender, EventArgs e)
        {
            if (textxt.Text == "0")
            {
                tetettetettet.Text = "0";
            }
            else if (textxt.Text == "")
            {
                tetettetettet.Text = "无";
            }
            else
            {
                tetettetettet.Text = "其他";
            }
        }
    }
}